package com.ctu.gzero.properties
{	
	public class Property
	{
		private const LOWER_LIMIT:String = "lowerLimit";
		private const UPPER_LIMIT:String = "upperLimit";
		private const ALL_LIMITS:String = "allLimits";
		private const NO_LIMITS:String = "noLimits";
		
		private var _default:Object;
		private var _name:String;		
		private var _limits:String;
		
		
		
		public function Property(name:String, object:Object)
		{
			super();
			_name = name;
			_default = object;
			_limits = ALL_LIMITS;
		}
		
		public function equalHelper(obj1:Object, obj2:Object):Boolean
		{
			return obj1 == obj2;
		}
		
		public function get name():String
		{
			return _name;
		}
		
		public function toXMLString(obj:Object):String
		{
			return obj.toString();
		}
		
		public function valueFromString(value:String):Object
		{
			return value;
		}
		
		public function hash(obj:Object, code:uint):uint
		{
			return 0;
		}
		
		public function initializeHelper(obj:Object):Object
		{
			return obj;
		}
		
		public function checkUpperLimit():Boolean
		{
			if(_limits==ALL_LIMITS)
			{
				return true;
			}			
			
			return _limits==LOWER_LIMIT;
			
		}
		
		public function checkLowerLimit():Boolean
		{
			if(_limits==ALL_LIMITS)
			{
				return true;
			}
			
			return _limits==LOWER_LIMIT;			
		}
		
		public function concatHelper(obj1:Object, obj2:Object):Object
		{
			return obj1==null ? obj2 : obj1;
		}
		
		public function get defaultValue():Object
		{
			return _default;
		}
		
		public function setHelper(obj1:Object, obj2:Object):Object
		{
			return obj2;
		}
		
		public static function shallowCopy(obj:Object):Object
		{
			var buffer:Object = new Object();
			
			for(var s:Object in obj)
			{				
				buffer[s] = obj[s];
			}						
			
			return buffer;
		}
		
		public static function equalAllHelper(obj1:Object, obj2:Object, obj3:Object):Boolean
		{
			var prop:Property = null;
			var name:String = null;;
			
			if(obj2==obj3)
			{
				return true;
			}
			
			if(obj2==null)
			{
				return false;
			}
			
			if(obj3==null)
			{
				return false;	
			}
			
			
			for each(var s:Property in obj1)
			{
				prop = s;
				name = prop.name; 
				if(!prop.equalHelper(obj2[name], obj3[name]))
				{
					return false;	
				} 
			}
			
			
			return true;
		}
		
		public static function defaultsAllHelper(obj1:Object, obj2:Object):void
		{
			var prop:Property;
			
			for each(var s:Property in obj1)
			{
				prop = s;
				obj2[prop.name] = prop.defaultValue;
			}
		}

	}
}